import { defineStore } from 'pinia';
import { KEY_USER } from '@/constant';
import {User} from '@/model/user';

interface UserState {
    user: User;
}

export const useUserStore = defineStore('user', {
    state: (): UserState => {
        return {
            user: new User(),
        };
    },
    actions: {
        remove() {
            Object.assign(this.user, new User());
        },
        setUser(user: User) {
            Object.assign(this.user, user);
        },
    },
    persist: {
        storage: sessionStorage,
        key: KEY_USER,
    },
});
